package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import com.greensock.*;

    public class JobsIndexShell extends Sprite
    {
        public var myXMLList:XMLList;
        var fadeSpeed:Number;
        var listLength:int;
        var jobsThumbnail:JobsThumbnail;
        var myRoot:MovieClip;
        var jobsArray:Array;
        var indexPoint:int;

        public function JobsIndexShell(param1:MovieClip, param2:Number, param3:XMLList, param4:int) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            myXMLList = param3;
            listLength = myXMLList.item.length();
            indexPoint = param4;
            jobsArray = new Array();
            buildJobsGrid();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        public function fadeOutShell() : void
        {
            TweenMax.to(this, fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                visible = false;
                return;
            }
            });
            return;
        }

        function doResize() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            while (_loc_1 < jobsArray.length)
            {
                
                jobsArray[_loc_1].x = Math.round(_loc_1 % 4 * 3 * (myRoot.unitW + myRoot.gutterW));
                jobsArray[_loc_1].y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH));
                _loc_1++;
            }
            return;
        }

        function jobOver(event:MouseEvent) : void
        {
            event.currentTarget.jobOver();
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function buildJobsGrid() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            _loc_1 = (indexPoint - 1) * 4;
            _loc_2 = _loc_1;
            while (_loc_2 < _loc_1 + 4)
            {
                
                if (myXMLList.item[_loc_2] != undefined)
                {
                    jobsArray.push(new JobsThumbnail(myRoot, fadeSpeed, myXMLList.item[_loc_2].@label, myXMLList.item[_loc_2].longTitle, _loc_2, myXMLList.item[_loc_2].@id));
                    jobsArray[(jobsArray.length - 1)].addEventListener(MouseEvent.ROLL_OVER, jobOver, false, 0, true);
                    jobsArray[(jobsArray.length - 1)].addEventListener(MouseEvent.ROLL_OUT, jobOut, false, 0, true);
                    jobsArray[(jobsArray.length - 1)].addEventListener(MouseEvent.CLICK, jobClick, false, 0, true);
                    jobsArray[(jobsArray.length - 1)].buttonMode = true;
                    jobsArray[(jobsArray.length - 1)].mouseChildren = false;
                    addChild(jobsArray[(jobsArray.length - 1)]);
                }
                _loc_2++;
            }
            return;
        }

        function jobOut(event:MouseEvent) : void
        {
            event.currentTarget.jobOut();
            return;
        }

        function jobClick(event:MouseEvent) : void
        {
            updateAddress(event.currentTarget.dbId);
            return;
        }

        function updateAddress(param1) : void
        {
            switch(myRoot.pathNames[2])
            {
                case "new-york":
                {
                    myRoot.clickPathNames = ["contact", "employment", "new-york", myRoot.pathNames[3], param1];
                    myRoot.updateAddress("/" + "contact" + "/" + "employment" + "/" + "new-york" + "/" + myRoot.pathNames[3] + "/" + param1 + "/");
                    break;
                }
                case "los-angeles":
                {
                    myRoot.clickPathNames = ["contact", "employment", "los-angeles", myRoot.pathNames[3], param1];
                    myRoot.updateAddress("/" + "contact" + "/" + "employment" + "/" + "los-angeles" + "/" + myRoot.pathNames[3] + "/" + param1 + "/");
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        public function fadeInShell() : void
        {
            visible = true;
            TweenMax.to(this, fadeSpeed, {alpha:1, delay:fadeSpeed, overwrite:true});
            return;
        }

    }
}
